import fs from 'fs';
import data from './data.json';

let employees = data;

export default {
  'GET /api/data': (_, response) => {
    response.send(employees);
  },
  'POST /api/data': (request, response) => {
    // response.setHeader('Access-Control-Allow-Origin', '*');
    const newData = request.body;
    console.log('mock_post', newData);
    employees = newData;
    fs.writeFileSync(__dirname + '/data.json', JSON.stringify(newData));
    response.end('ok');
  },
};
